﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrossQuery
{
    public class AreaType : IType
    {

        private List<AreaData> area_list;
        private string selected_area;

        public AreaType()
        {
            area_list = new List<AreaData>();
            selected_area = "";
        }

        public string Value
        {
            get { return SelectedArea; }
            set { SelectedArea = value; }
        }

        public string Type
        {
            get { return "Area"; }
        }

        public List<AreaData> AreaList
        {
            get { return area_list; }
            set { area_list = value; }
        }

        public string SelectedArea
        {
            get { return selected_area; }
            set { selected_area = value; }
        }

        public string ToSQLString()
        {
            foreach (AreaData data in area_list)
            {
                if (data.AreaString == selected_area)
                    return "'" + data.AreaCode + "'";
            }
            return "'-1'";
        }

        public override string ToString()
        {
            foreach (AreaData data in area_list)
            {
                if (data.AreaString == selected_area)
                    return data.AreaString;
            }
            return "";
        }

    }

    public class AreaData
    {
        private KeyValuePair<string, string> area;

        public AreaData(string areaCode, string areaString)
        {
            area = new KeyValuePair<string, string>(areaCode, areaString);
        }

        public string AreaCode
        {
            get { return area.Key; }
        }

        public string AreaString
        {
            get { return area.Value; }
        }
    }
}
